package com.thinvent.nj.ais.controller.jtlfx;

import com.alibaba.fastjson.JSONObject;
import com.thinvent.nj.common.rest.ResponseEntity;
import com.thinvent.nj.common.util.MapperUtil;
import com.thinvent.nj.ais.service.JtlService;
import com.thinvent.nj.common.page.Page;
import com.thinvent.nj.ais.entity.Jtl;
import com.thinvent.nj.web.controller.BaseViewController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* 交通量列表 Controller
* @author administrator
* @date 2018-7-16
*/
@Controller
@RequestMapping(path = "/jtlfx/jtls")
public class JtlController extends BaseViewController {

    @Autowired
    private JtlService jtlService;

    @RequiresPermissions("jtl:view")
    @RequestMapping(method = RequestMethod.GET)
    public String toHtml() {
        return "jtlfx/jtlList";
    }


    @RequestMapping(path = "/search/page", method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity findTableData(@RequestBody Map<String, Object> params) {
        Page<Jtl> target = jtlService.findPage(getQueryParameter(params), getQueryMsg(params));
        return ResponseEntity.ok(target);
    }

    @RequestMapping(path = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity get(@PathVariable("id") String id) {
        return ResponseEntity.ok(jtlService.get(id));
    }

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity insert(@RequestBody Map<String, Object> params) {
        Jtl target = new Jtl();
        MapperUtil.copy(params, target);

        jtlService.insert(target);

        return ResponseEntity.ok();
    }


    @RequestMapping(path = "/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public ResponseEntity update(@PathVariable("id") String id, @RequestBody Map<String, Object> params) {
        Jtl target = jtlService.get(id);
        MapperUtil.copy(params, target);

        jtlService.update(target);

        return ResponseEntity.ok();
    }

    @RequestMapping(path = "/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public ResponseEntity del(@PathVariable("id") String id) {
        jtlService.delete(id);
        return ResponseEntity.ok();
    }



}
